angular.module('todoApp').directive('todoBody', function() {
  return {
    templateUrl: './directives/todoBody.html',
    scope: {
      list: '=list',
      undo: '&onUndo',
      archive: '&onArchive',
      archiveAll: '&onArchiveAll'
    },
    link: function(scope) {
      scope.checkedList = [];
      scope.uncheckedList = [];
      scope.$watch('list', function() {
        scope.checkedList = scope.list.filter(item => item.checked);
        scope.uncheckedList = scope.list.filter(item => !item.checked);
      }, true); // 使用deep watch

      // scope.undo = function(index) {
      //   console.log(index)
      //   scope.uncheckedList[index].checked = false;
      // }
      // scope.archive = function(index) {
      //   scope.uncheckedList[index].archived = true;
      // }
    }
  };
});